package com.itheima.controller;

import com.itheima.pojo.Emp;
import com.itheima.pojo.PageList;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * 员工管理Controller
 */
@RestController
public class EmpController {

    @Autowired
    private EmpService empService;

    @GetMapping("/emps")
    public Result empList(@RequestParam Integer page, @RequestParam Integer pageSize, String name, Short gender, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){

        //拿到总的页数。

        //拿到rows 结果结婚

        //封装到PageList返回

        System.out.println("获取到参数page"+page+"获取到参数pageSize"+pageSize);

        List<Emp> lists=empService.getList( page,pageSize,name,gender,begin,end);
        System.out.println(lists);

        System.out.println(name);
        System.out.println(gender);
        System.out.println(begin);
        System.out.println(end);

        Long counts=empService.getCout();

        PageList pglist=new PageList(counts,lists);


        Result.success(pglist);


        return Result.success(pglist);
    }

//    public List<Emp> empList(){
//    public HashMap<String,Object> empList(@RequestParam Integer page,@RequestParam Integer pageSize){
//
//        System.out.println("获取到参数page"+page+"获取到参数pageSize"+pageSize);
//
//        List<Emp> lists=empService.getList( page,pageSize);
//        System.out.println(lists);
//
//        HashMap<String,Object> hm =new HashMap<>();
//        hm.put("code",1);
//        hm.put("msg","success");
//
//        HashMap<String,Object> data=new HashMap<>();
//        data.put("total",12);
//        data.put("rows",lists);
//
//        hm.put("data",data);
//
//        return hm;
//    }


    @DeleteMapping("/emps/{ids}")
    public  Result  deletes(@PathVariable("ids") List<Integer> list_ids){
//        System.out.println(ids);
//
//        String[] strArray = ids.split(",");
//        List<String> list_ids = Arrays.asList(strArray);
//
//        System.out.println(list_ids);

        System.out.println(list_ids);


        empService.deletes(list_ids);

        return Result.success(null);

    }
}
